home *** CD-ROM | disk | FTP | other *** search
/ Aminet 24 / Aminet 24 (1998)(GTI - Schatztruhe)[!][Apr 1998].iso / Aminet / dev / e / AEPD24.lha / EPD24 / Amiga_E-Programme / FVList / FVNodeTest1.e < prev    next >
Text File  |  1980-02-01  |  2KB  |  64 lines

  1. /* FVList class in use:
  2.     Let's build a list of aliens for some game
  3. */
  4. /*--------------------------------------------------------------------------*/
  5. MODULE 'FVMods/FVList'
  6. /*--------------------------------------------------------------------------*/
  7. OBJECT alien OF fvnode
  8.     alientype:LONG            -> give the alien some silly attributes
  9.     speed:LONG
  10.     speedincrease:LONG
  11. ENDOBJECT
  12. /*--------------------------------------------------------------------------*/
  13. PROC addAlien(root,type,speed,speedincrease) OF alien
  14.      self::fvnode.make(root)
  15.      self.alientype := type
  16.      self.speed := speed
  17.      self.speedincrease := speedincrease
  18. ENDPROC
  19. /*--------------------------------------------------------------------------*/
  20. PROC show() OF alien
  21.     PrintF('Node:\n\taddress=\h\n\tchild=\h\n\troot=\h\n\tAlienType = \d\n\tAlienSpeed = \d\n\tAlienSpeedincrease = \d\n-------------------\n',self,self.giveChild(),self.giveRoot(),self.alientype,self.speed,self.speedincrease)
  22. ENDPROC
  23. /*--------------------------------------------------------------------------*/
  24. PROC    increaseAlienSpeeds(r:PTR TO fvlist)
  25.      DEF a:PTR TO alien
  26.  
  27.     IF (a := r.giveChild())
  28.         PrintF('Increasing alien speeds\n')
  29.         WHILE a
  30.                a.speed := a.speed + a.speedincrease
  31.             a := a.giveChild()
  32.         ENDWHILE
  33.     ELSE
  34.          PrintF('Cannot increase alien speeds, because list is empty\n')
  35.     ENDIF
  36. ENDPROC
  37. /*--------------------------------------------------------------------------*/
  38. PROC main()
  39.     DEF    root:PTR TO fvlist,
  40.         node:PTR TO alien,
  41.         intermediate:PTR TO alien
  42.  
  43.     Delay(50)
  44.     NEW root.make(NIL)
  45.     NEW node.addAlien(root,1,26,1)
  46.     intermediate := NEW node.addAlien(root,5,15,2)
  47.     NEW node.addAlien(root,2,32,3)
  48.     root.show()
  49.     increaseAlienSpeeds(root)    -> let's do something useful :) with the alien members
  50.     PrintF('Pausing...\n')
  51.     Delay(100)
  52.     root.show()
  53.  
  54.     PrintF('Killing an alien: alien \h... DIE!\n',intermediate)
  55.     intermediate.delete()        -> kill'im
  56.     PrintF('Pausing...\n')
  57.     Delay(100)
  58.     root.show()
  59.  
  60.     PrintF('\nquitting...\nnow,root = \h\n',root)
  61.      END root                    -> frees root and all linked nodes too
  62.     PrintF('root = \h, if it is 0, then root is also freed.\n',root)
  63. ENDPROC
  64.